from typing import List

class Solution:
    def coinChange(self, coins: List[int], amount: int) -> int:
        """
        动态规划解法，力扣322. 零钱兑换
        :param coins: 可用的硬币面额
        :param amount: 目标金额
        :return: 最少硬币数，无法凑出返回-1
        """
        dp = [float('inf')] * (amount + 1)
        dp[0] = 0
        for coin in coins:
            for x in range(coin, amount + 1):
                dp[x] = min(dp[x], dp[x - coin] + 1)
        return dp[amount] if dp[amount] != float('inf') else -1
